package lanternutil

import (
	"os"

	"strings"

	"git.oschina.net/haixiang42/goutil/fileutil"
)

const (
	LanternConfigFile = "lantern\\settings.yaml"
)

func LanternConfig() (map[string]string, error) {
	appdataPath := os.Getenv("appdata")
	cfgFileName := appdataPath + "\\" + LanternConfigFile
	result := make(map[string]string)
	err := fileutil.EachLineFile(cfgFileName, func(line string) {
		runes := []rune(line)
		index := strings.IndexFunc(line, func(r rune) bool {
			return r == ':'
		})
		result[string(runes[0:index])] = strings.TrimSpace(string(runes[index+1:]))
	})
	if err != nil {
		return nil, err
	}
	return result, nil
}
